home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: strange segementtation fault w/ fprintf
- Date: 15 Feb 96 00:00:36 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824342436@rscernix>
- References: <312215BE.41C6@di.epfl.ch>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <312215BE.41C6@di.epfl.ch> Olivier Georg <ogeorg@di.epfl.ch> writes:
-
- >value. But when the first fprintf is reached, I get
- >a segmentation fault... using GDB, I did a "where" where
- >the seg. fault occured, and here is the result:
- >
- >(gdb) where
- >#0 0xfabc814 in __malloc () at malloc.c:303
- >#1 0xfabf1e4 in _malloc () at malloc.c:484
- >#2 0xfac6830 in _findbuf () at _findbuf.c:96
- >#3 0xfabca38 in _doprnt () at doprnt.c:1588
- >#4 0xfac7ffc in fprintf () at fprintf.c:45
- >#5 0x402c04 in writevector (fp=0xfb52914, len=128, vect=0x100022f0) at
- >mlutil.c:99
- >#6 0x40256c in main () at online.c:219
-
- fprintf is a red herring. What you show here is a typical case
- of corrupted malloc arena. You did bad things with pointers somewhere
- else in the code (probably wrote something in front or after a malloc'ed
- memory block) and corrupted your heap. When fprintf tries to malloc
- a buffer for the 'fp' stream, the segmentation fault occurs.
-
- If you can't find the bug in your code yourself, try to use a malloc
- debugging tool, e.g. ElectricFence which is free and available at many
- FTP servers (ask archie to find it).
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-